7 * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
9 if( defined( 'MEDIAWIKI' ) ) {
13 if($wgUseTeX) require_once( 'Math.php' );
20 var $mHeaders, $mMetatags, $mKeywords;
21 var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
22 var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
23 var $mSubtitle, $mRedirect, $mStatusCode;
24 var $mLastModified, $mETag, $mCategoryLinks;
25 var $mScripts, $mLinkColours;
27 var $mSuppressQuickbar;
30 var $mContainsOldMagic, $mContainsNewMagic;
31 var $mIsArticleRelated;
33 var $mShowFeedLinks = false;
34 var $mEnableClientCache = true;
35 var $mArticleBodyOnly = false;
39 * Initialise private variables
41 function OutputPage() {
42 $this->mHeaders
= $this->mMetatags
=
43 $this->mKeywords
= $this->mLinktags
= array();
44 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
45 $this->mRedirect
= $this->mLastModified
=
46 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
=
47 $this->mOnloadHandler
= '';
48 $this->mIsArticleRelated
= $this->mIsarticle
= $this->mPrintable
= true;
49 $this->mSuppressQuickbar
= $this->mPrintable
= false;
50 $this->mLanguageLinks
= array();
51 $this->mCategoryLinks
= array() ;
52 $this->mDoNothing
= false;
53 $this->mContainsOldMagic
= $this->mContainsNewMagic
= 0;
54 $this->mParserOptions
= ParserOptions
::newFromUser( $temp = NULL );
55 $this->mSquidMaxage
= 0;
58 $this->mRevisionId
= null;
61 function addHeader( $name, $val ) { array_push( $this->mHeaders
, $name.': '.$val ) ; }
62 function redirect( $url, $responsecode = '302' ) { $this->mRedirect
= $url; $this->mRedirectCode
= $responsecode; }
63 function setStatusCode( $statusCode ) { $this->mStatusCode
= $statusCode; }
65 # To add an http-equiv meta tag, precede the name with "http:"
66 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
67 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
68 function addScript( $script ) { $this->mScripts
.= $script; }
69 function getScript() { return $this->mScripts
; }
71 function setETag($tag) { $this->mETag
= $tag; }
72 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
73 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
75 function addLink( $linkarr ) {
76 # $linkarr should be an associative array of attributes. We'll escape on output.
77 array_push( $this->mLinktags
, $linkarr );
80 function addMetadataLink( $linkarr ) {
81 # note: buggy CC software only reads first "meta" link
82 static $haveMeta = false;
83 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
84 $this->addLink( $linkarr );
89 * checkLastModified tells the client to use the client-cached page if
90 * possible. If sucessful, the OutputPage is disabled so that
91 * any future call to OutputPage->output() have no effect. The method
92 * returns true iff cache-ok headers was sent.
94 function checkLastModified ( $timestamp ) {
95 global $wgCachePages, $wgUser;
96 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
97 wfDebug( "CACHE DISABLED, NO TIMESTAMP\n" );
100 if( !$wgCachePages ) {
101 wfDebug( "CACHE DISABLED\n", false );
104 if( $wgUser->getOption( 'nocache' ) ) {
105 wfDebug( "USER DISABLED CACHE\n", false );
109 $timestamp=wfTimestamp(TS_MW
,$timestamp);
110 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
) );
112 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
113 # IE sends sizes after the date like this:
114 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
115 # this breaks strtotime().
116 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
117 $modsinceTime = strtotime( $modsince );
118 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
119 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
120 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
121 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) ) {
122 # Make sure you're in a place you can leave when you call us!
123 header( "HTTP/1.0 304 Not Modified" );
124 $this->mLastModified
= $lastmod;
125 $this->sendCacheControl();
126 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
128 @ob_end_clean
(); // Don't output compressed blob
131 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
132 $this->mLastModified
= $lastmod;
135 wfDebug( "client did not send If-Modified-Since header\n", false );
136 $this->mLastModified
= $lastmod;
140 function getPageTitleActionText () {
149 // Display title is already customized
152 return wfMsg('history_short');
154 // FIXME: bug 2735; not correct for special pages etc
155 return wfMsg('preview');
157 return wfMsg('info_short');
163 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
164 function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
165 function setPageTitle( $name ) {
166 global $action, $wgContLang;
167 $name = $wgContLang->convert($name, true);
168 $this->mPagetitle
= $name;
169 if(!empty($action)) {
170 $taction = $this->getPageTitleActionText();
171 if( !empty( $taction ) ) {
172 $name .= ' - '.$taction;
176 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
178 function getHTMLTitle() { return $this->mHTMLtitle
; }
179 function getPageTitle() { return $this->mPagetitle
; }
180 function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
181 function getSubtitle() { return $this->mSubtitle
; }
182 function isArticle() { return $this->mIsarticle
; }
183 function setPrintable() { $this->mPrintable
= true; }
184 function isPrintable() { return $this->mPrintable
; }
185 function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
186 function isSyndicated() { return $this->mShowFeedLinks
; }
187 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
188 function getOnloadHandler() { return $this->mOnloadHandler
; }
189 function disable() { $this->mDoNothing
= true; }
191 function setArticleRelated( $v ) {
192 $this->mIsArticleRelated
= $v;
194 $this->mIsarticle
= false;
197 function setArticleFlag( $v ) {
198 $this->mIsarticle
= $v;
200 $this->mIsArticleRelated
= $v;
204 function isArticleRelated() { return $this->mIsArticleRelated
; }
206 function getLanguageLinks() { return $this->mLanguageLinks
; }
207 function addLanguageLinks($newLinkArray) {
208 $this->mLanguageLinks +
= $newLinkArray;
210 function setLanguageLinks($newLinkArray) {
211 $this->mLanguageLinks
= $newLinkArray;
214 function getCategoryLinks() {
215 return $this->mCategoryLinks
;
219 * Add an array of categories, with names in the keys
221 function addCategoryLinks($categories) {
222 global $wgUser, $wgLinkCache, $wgContLang;
224 # Add the links to the link cache in a batch
225 $arr = array( NS_CATEGORY
=> $categories );
227 $lb->setArray( $arr );
228 $lb->execute( $wgLinkCache );
230 $sk =& $wgUser->getSkin();
231 foreach ( $categories as $category => $arbitrary ) {
232 $title = Title
::makeTitleSafe( NS_CATEGORY
, $category );
233 $text = $wgContLang->convertHtml( $title->getText() );
234 $this->mCategoryLinks
[] = $sk->makeLinkObj( $title, $text );
238 function setCategoryLinks($categories) {
239 $this->mCategoryLinks
= array();
240 $this->addCategoryLinks($categories);
243 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
244 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
246 function addHTML( $text ) { $this->mBodytext
.= $text; }
247 function clearHTML() { $this->mBodytext
= ''; }
248 function getHTML() { return $this->mBodytext
; }
249 function debug( $text ) { $this->mDebugtext
.= $text; }
252 function setParserOptions( $options ) {
253 return $this->ParserOptions( $options );
256 function ParserOptions( $options = null ) {
257 return wfSetVar( $this->mParserOptions
, $options );
261 * Set the revision ID which will be seen by the wiki text parser
262 * for things such as embedded {{REVISIONID}} variable use.
263 * @param mixed $revid an integer, or NULL
264 * @return mixed previous value
266 function setRevisionId( $revid ) {
267 $val = is_null( $revid ) ?
null : intval( $revid );
268 return wfSetVar( $this->mRevisionId
, $val );
272 * Convert wikitext to HTML and add it to the buffer
273 * Default assumes that the current page title will
276 function addWikiText( $text, $linestart = true ) {
278 $this->addWikiTextTitle($text, $wgTitle, $linestart);
281 function addWikiTextWithTitle($text, &$title, $linestart = true) {
282 $this->addWikiTextTitle($text, $title, $linestart);
285 function addWikiTextTitle($text, &$title, $linestart) {
287 $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions
,
288 $linestart, true, $this->mRevisionId
);
289 $this->addParserOutput( $parserOutput );
292 function addParserOutputNoText( &$parserOutput ) {
293 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
294 $this->addCategoryLinks( $parserOutput->getCategories() );
295 $this->addKeywords( $parserOutput );
296 if ( $parserOutput->getCacheTime() == -1 ) {
297 $this->enableClientCache( false );
301 function addParserOutput( &$parserOutput ) {
302 $this->addParserOutputNoText( $parserOutput );
303 $this->addHTML( $parserOutput->getText() );
307 * Add wikitext to the buffer, assuming that this is the primary text for a page view
308 * Saves the text into the parser cache if possible
310 function addPrimaryWikiText( $text, $article, $cache = true ) {
311 global $wgParser, $wgParserCache, $wgUser;
313 $parserOutput = $wgParser->parse( $text, $article->mTitle
,
314 $this->mParserOptions
, true, true, $this->mRevisionId
);
316 if ( $article && $parserOutput->getCacheTime() != -1 ) {
317 $wgParserCache->save( $parserOutput, $article, $wgUser );
320 $this->addParserOutput( $parserOutput );
324 * Add the output of a QuickTemplate to the output buffer
325 * @param QuickTemplate $template
327 function addTemplate( &$template ) {
329 $template->execute();
330 $this->addHTML( ob_get_contents() );
335 * Parse wikitext and return the HTML. This is for special pages that add the text later
337 function parse( $text, $linestart = true ) {
338 global $wgParser, $wgTitle;
339 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
,
340 $linestart, true, $this->mRevisionId
);
341 return $parserOutput->getText();
350 function tryParserCache( $article, $user ) {
351 global $wgParserCache;
352 $parserOutput = $wgParserCache->get( $article, $user );
353 if ( $parserOutput !== false ) {
354 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
355 $this->addCategoryLinks( $parserOutput->getCategories() );
356 $this->addKeywords( $parserOutput );
357 $this->addHTML( $parserOutput->getText() );
358 $t = $parserOutput->getTitleText();
360 $this->setPageTitle( $t );
369 * Set the maximum cache time on the Squid in seconds
372 function setSquidMaxage( $maxage ) {
373 $this->mSquidMaxage
= $maxage;
377 * Use enableClientCache(false) to force it to send nocache headers
380 function enableClientCache( $state ) {
381 return wfSetVar( $this->mEnableClientCache
, $state );
384 function uncacheableBecauseRequestvars() {
386 return $wgRequest->getText('useskin', false) === false
387 && $wgRequest->getText('uselang', false) === false;
390 function sendCacheControl() {
391 global $wgUseSquid, $wgUseESI;
394 header("ETag: $this->mETag");
396 # don't serve compressed data to clients who can't handle it
397 # maintain different caches for logged-in users and non-logged in ones
398 header( 'Vary: Accept-Encoding, Cookie' );
399 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
400 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
401 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
404 # We'll purge the proxy cache explicitly, but require end user agents
405 # to revalidate against the proxy on each visit.
406 # Surrogate-Control controls our Squid, Cache-Control downstream caches
407 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
408 # start with a shorter timeout for initial testing
409 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
410 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
411 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
413 # We'll purge the proxy cache for anons explicitly, but require end user agents
414 # to revalidate against the proxy on each visit.
415 # IMPORTANT! The Squid needs to replace the Cache-Control header with
416 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
417 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
418 # start with a shorter timeout for initial testing
419 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
420 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
423 # We do want clients to cache if they can, but they *must* check for updates
424 # on revisiting the page.
425 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
426 header( "Expires: -1" );
427 header( "Cache-Control: private, must-revalidate, max-age=0" );
429 if($this->mLastModified
) header( "Last-modified: {$this->mLastModified}" );
431 wfDebug( "** no caching **\n", false );
433 # In general, the absence of a last modified header should be enough to prevent
434 # the client from using its cache. We send a few other things just to make sure.
435 header( 'Expires: -1' );
436 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
437 header( 'Pragma: no-cache' );
442 * Finally, all the text has been munged and accumulated into
443 * the object, let's actually output it:
446 global $wgUser, $wgOutputEncoding;
447 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType, $wgProfiler;
449 if( $this->mDoNothing
){
452 $fname = 'OutputPage::output';
453 wfProfileIn( $fname );
454 $sk = $wgUser->getSkin();
456 if ( '' != $this->mRedirect
) {
457 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
458 # Standards require redirect URLs to be absolute
460 $this->mRedirect
= $wgServer . $this->mRedirect
;
462 if( $this->mRedirectCode
== '301') {
463 if( !$wgDebugRedirects ) {
464 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
466 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
469 $this->sendCacheControl();
471 if( $wgDebugRedirects ) {
472 $url = htmlspecialchars( $this->mRedirect
);
473 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
474 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
475 print "</body>\n</html>\n";
477 header( 'Location: '.$this->mRedirect
);
479 if ( isset( $wgProfiler ) ) { wfDebug( $wgProfiler->getOutput() ); }
480 wfProfileOut( $fname );
483 elseif ( $this->mStatusCode
)
485 $statusMessage = array(
487 101 => 'Switching Protocols',
492 203 => 'Non-Authoritative Information',
494 205 => 'Reset Content',
495 206 => 'Partial Content',
496 207 => 'Multi-Status',
497 300 => 'Multiple Choices',
498 301 => 'Moved Permanently',
501 304 => 'Not Modified',
503 307 => 'Temporary Redirect',
504 400 => 'Bad Request',
505 401 => 'Unauthorized',
506 402 => 'Payment Required',
509 405 => 'Method Not Allowed',
510 406 => 'Not Acceptable',
511 407 => 'Proxy Authentication Required',
512 408 => 'Request Timeout',
515 411 => 'Length Required',
516 412 => 'Precondition Failed',
517 413 => 'Request Entity Too Large',
518 414 => 'Request-URI Too Large',
519 415 => 'Unsupported Media Type',
520 416 => 'Request Range Not Satisfiable',
521 417 => 'Expectation Failed',
522 422 => 'Unprocessable Entity',
524 424 => 'Failed Dependency',
525 500 => 'Internal Server Error',
526 501 => 'Not Implemented',
527 502 => 'Bad Gateway',
528 503 => 'Service Unavailable',
529 504 => 'Gateway Timeout',
530 505 => 'HTTP Version Not Supported',
531 507 => 'Insufficient Storage'
534 if ( $statusMessage[$this->mStatusCode
] )
535 header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
538 # Buffer output; final headers may depend on later processing
541 # Disable temporary placeholders, so that the skin produces HTML
542 $sk->postParseLinkColour( false );
544 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
545 header( 'Content-language: '.$wgContLanguageCode );
547 if ($this->mArticleBodyOnly
) {
548 $this->out($this->mBodytext
);
550 wfProfileIn( 'Output-skin' );
551 $sk->outputPage( $this );
552 wfProfileOut( 'Output-skin' );
555 $this->sendCacheControl();
557 wfProfileOut( $fname );
560 function out( $ins ) {
561 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
562 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
565 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
566 if ( false === $outs ) { $outs = $ins; }
571 function setEncodings() {
572 global $wgInputEncoding, $wgOutputEncoding;
573 global $wgUser, $wgContLang;
575 $wgInputEncoding = strtolower( $wgInputEncoding );
577 if( $wgUser->getOption( 'altencoding' ) ) {
578 $wgContLang->setAltEncoding();
582 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
583 $wgOutputEncoding = strtolower( $wgOutputEncoding );
586 $wgOutputEncoding = $wgInputEncoding;
590 * Returns a HTML comment with the elapsed time since request.
591 * This method has no side effects.
592 * Use wfReportTime() instead.
596 function reportTime() {
597 $time = wfReportTime();
602 * Note: these arguments are keys into wfMsg(), not text!
604 function errorpage( $title, $msg ) {
607 $this->mDebugtext
.= 'Original title: ' .
608 $wgTitle->getPrefixedText() . "\n";
609 $this->setPageTitle( wfMsg( $title ) );
610 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
611 $this->setRobotpolicy( 'noindex,nofollow' );
612 $this->setArticleRelated( false );
613 $this->enableClientCache( false );
614 $this->mRedirect
= '';
616 $this->mBodytext
= '';
617 $this->addWikiText( wfMsg( $msg ) );
618 $this->returnToMain( false );
625 * Display an error page indicating that a given version of MediaWiki is
628 * @param mixed $version The version of MediaWiki needed to use the page
630 function versionRequired( $version ) {
633 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
634 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
635 $this->setRobotpolicy( 'noindex,nofollow' );
636 $this->setArticleRelated( false );
637 $this->mBodytext
= '';
639 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
640 $this->returnToMain();
644 * Display an error page noting that a given permission bit is required.
645 * This should generally replace the sysopRequired, developerRequired etc.
646 * @param string $permission key required
648 function permissionRequired( $permission ) {
651 $this->setPageTitle( wfMsg( 'badaccess' ) );
652 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
653 $this->setRobotpolicy( 'noindex,nofollow' );
654 $this->setArticleRelated( false );
655 $this->mBodytext
= '';
657 $sk = $wgUser->getSkin();
658 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
659 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
660 $this->returnToMain();
666 function sysopRequired() {
669 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
670 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
671 $this->setRobotpolicy( 'noindex,nofollow' );
672 $this->setArticleRelated( false );
673 $this->mBodytext
= '';
675 $sk = $wgUser->getSkin();
676 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
677 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
678 $this->returnToMain();
684 function developerRequired() {
687 $this->setPageTitle( wfMsg( 'developertitle' ) );
688 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
689 $this->setRobotpolicy( 'noindex,nofollow' );
690 $this->setArticleRelated( false );
691 $this->mBodytext
= '';
693 $sk = $wgUser->getSkin();
694 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
695 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
696 $this->returnToMain();
699 function loginToUse() {
700 global $wgUser, $wgTitle, $wgContLang;
702 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
703 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
704 $this->setRobotpolicy( 'noindex,nofollow' );
705 $this->setArticleFlag( false );
706 $this->mBodytext
= '';
707 $loginpage = Title
::makeTitle(NS_SPECIAL
, 'Userlogin');
708 $sk = $wgUser->getSkin();
709 $loginlink = $sk->makeKnownLinkObj($loginpage, wfMsg('loginreqlink'),
710 'returnto=' . htmlspecialchars($wgTitle->getPrefixedDBkey()));
711 $this->addHTML( wfMsgHtml( 'loginreqpagetext', $loginlink ) );
713 # We put a comment in the .html file so a Sysop can diagnose the page the
715 $this->addHTML( "\n<!--" .
716 $wgContLang->getNsText( $wgTitle->getNamespace() ) .
718 $wgTitle->getDBkey() . '-->' );
719 $this->returnToMain(); # Flip back to the main page after 10 seconds.
722 function databaseError( $fname, $sql, $error, $errno ) {
723 global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
725 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
726 $this->setRobotpolicy( 'noindex,nofollow' );
727 $this->setArticleRelated( false );
728 $this->enableClientCache( false );
729 $this->mRedirect
= '';
731 if( !$wgShowSQLErrors ) {
732 $sql = wfMsg( 'sqlhidden' );
735 if ( $wgCommandLineMode ) {
736 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
737 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
739 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
740 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
743 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
747 $this->mBodytext
= $msg;
752 function readOnlyPage( $source = null, $protected = false ) {
753 global $wgUser, $wgReadOnlyFile, $wgReadOnly;
755 $this->setRobotpolicy( 'noindex,nofollow' );
756 $this->setArticleRelated( false );
759 $this->setPageTitle( wfMsg( 'viewsource' ) );
760 $this->addWikiText( wfMsg( 'protectedtext' ) );
762 $this->setPageTitle( wfMsg( 'readonly' ) );
764 $reason = $wgReadOnly;
766 $reason = file_get_contents( $wgReadOnlyFile );
768 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
771 if( is_string( $source ) ) {
772 if( strcmp( $source, '' ) == 0 ) {
774 if ( $wgTitle->getNamespace() == NS_MEDIAWIKI
) {
775 $source = wfMsgWeirdKey ( $wgTitle->getText() ) ;
777 $source = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
780 $rows = $wgUser->getOption( 'rows' );
781 $cols = $wgUser->getOption( 'cols' );
782 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
783 htmlspecialchars( $source ) . "\n</textarea>";
784 $this->addHTML( $text );
787 $this->returnToMain( false );
790 function fatalError( $message ) {
791 $this->setPageTitle( wfMsg( "internalerror" ) );
792 $this->setRobotpolicy( "noindex,nofollow" );
793 $this->setArticleRelated( false );
794 $this->enableClientCache( false );
795 $this->mRedirect
= '';
797 $this->mBodytext
= $message;
802 function unexpectedValueError( $name, $val ) {
803 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
806 function fileCopyError( $old, $new ) {
807 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
810 function fileRenameError( $old, $new ) {
811 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
814 function fileDeleteError( $name ) {
815 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
818 function fileNotFoundError( $name ) {
819 $this->fatalError( wfMsg( 'filenotfound', $name ) );
823 * return from error messages or notes
824 * @param $auto automatically redirect the user after 10 seconds
825 * @param $returnto page title to return to. Default is Main Page.
827 function returnToMain( $auto = true, $returnto = NULL ) {
828 global $wgUser, $wgOut, $wgRequest;
830 if ( $returnto == NULL ) {
831 $returnto = $wgRequest->getText( 'returnto' );
833 $returnto = htmlspecialchars( $returnto );
835 $sk = $wgUser->getSkin();
836 if ( '' == $returnto ) {
837 $returnto = wfMsgForContent( 'mainpage' );
839 $link = $sk->makeKnownLink( $returnto, '' );
841 $r = wfMsg( 'returnto', $link );
843 $titleObj = Title
::newFromText( $returnto );
844 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
846 $wgOut->addHTML( "\n<p>$r</p>\n" );
850 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
851 * and uses the first 10 of them for META keywords
853 function addKeywords( &$parserOutput ) {
855 $this->addKeyword( $wgTitle->getPrefixedText() );
857 $links2d =& $parserOutput->getLinks();
858 foreach ( $links2d as $ns => $dbkeys ) {
859 foreach( $dbkeys as $dbkey => $id ) {
860 $this->addKeyword( $dbkey );
861 if ( ++
$count > 10 ) {
872 function headElement() {
873 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
874 global $wgUser, $wgContLang, $wgRequest, $wgUseTrackbacks, $wgTitle;
876 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
877 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
882 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
884 if ( '' == $this->getHTMLTitle() ) {
885 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
888 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
889 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
890 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
891 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
893 $ret .= $this->getHeadLinks();
895 if( $this->isPrintable() ) {
898 $media = "media='print'";
900 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
901 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
903 $sk = $wgUser->getSkin();
904 $ret .= $sk->getHeadScripts();
905 $ret .= $this->mScripts
;
906 $ret .= $sk->getUserStyles();
908 if ($wgUseTrackbacks && $this->isArticleRelated())
909 $ret .= $wgTitle->trackbackRDF();
915 function getHeadLinks() {
916 global $wgRequest, $wgStylePath;
918 foreach ( $this->mMetatags
as $tag ) {
919 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
921 $tag[0] = substr( $tag[0], 5 );
925 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
928 $p = $this->mRobotpolicy
;
929 if( $p !== '' && $p != 'index,follow' ) {
930 // http://www.robotstxt.org/wc/meta-user.html
931 // Only show if it's different from the default robots policy
932 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
935 if ( count( $this->mKeywords
) > 0 ) {
940 $ret .= "<meta name=\"keywords\" content=\"" .
941 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
943 foreach ( $this->mLinktags
as $tag ) {
945 foreach( $tag as $attr => $val ) {
946 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
950 if( $this->isSyndicated() ) {
951 # FIXME: centralize the mime-type and name information in Feed.php
952 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
953 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
954 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
955 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
962 * Turn off regular page output and return an error reponse
963 * for when rate limiting has triggered.
967 function rateLimited() {
970 wfHttpError( 500, 'Internal Server Error',
971 'Sorry, the server has encountered an internal error. ' .
972 'Please wait a moment and hit "refresh" to submit the request again.' );